/*********************************************************************
	Rhapsody	: 8.0
	Login		: Andrzej
	Component	: DefaultComponent
	Configuration 	: DefaultConfig
	Model Element	: Probe
//!	Generated Date	: Fri, 14, Dec 2012 
	File Path	: DefaultComponent/DefaultConfig/Default/Probe.java
*********************************************************************/

package Default;

//## auto_generated
import com.ibm.rational.rhapsody.oxf.*;
//## auto_generated
import com.ibm.rational.rhapsody.oxf.states.*;

//----------------------------------------------------------------------------
// Default/Probe.java                                                                  
//----------------------------------------------------------------------------

//## package Default 


//## class Probe 
public class Probe implements RiJStateConcept {
    
    public Reactive reactive;		//## ignore 
    
    protected boolean isBroken = false;		//## attribute isBroken 
    
    protected double temperature = 27.0;		//## attribute temperature 
    
    protected TemperatureMeasurer parent;		//## link parent 
    
    //#[ ignore 
    public static final int RiJNonState=0;
    public static final int WaitForNewTemperature=1;
    public static final int sendaction_9=2;
    public static final int sendaction_8=3;
    public static final int sendaction_7=4;
    //#]
    protected int rootState_subState;		//## ignore 
    
    protected int rootState_active;		//## ignore 
    
    public static final int Probe_Timeout_sendaction_7_id = 1;		//## ignore 
    
    
    //## statechart_method 
    public RiJThread getThread() {
        return reactive.getThread();
    }
    
    //## statechart_method 
    public void schedTimeout(long delay, long tmID, RiJStateReactive reactive) {
        getThread().schedTimeout(delay, tmID, reactive);
    }
    
    //## statechart_method 
    public void unschedTimeout(long tmID, RiJStateReactive reactive) {
        getThread().unschedTimeout(tmID, reactive);
    }
    
    //## statechart_method 
    public boolean isIn(int state) {
        return reactive.isIn(state);
    }
    
    //## statechart_method 
    public boolean isCompleted(int state) {
        return reactive.isCompleted(state);
    }
    
    //## statechart_method 
    public RiJEventConsumer getEventConsumer() {
        return (RiJEventConsumer)reactive;
    }
    
    //## statechart_method 
    public void gen(RiJEvent event) {
        reactive._gen(event);
    }
    
    //## statechart_method 
    public void queueEvent(RiJEvent event) {
        reactive.queueEvent(event);
    }
    
    //## statechart_method 
    public int takeEvent(RiJEvent event) {
        return reactive.takeEvent(event);
    }
    
    // Constructors
    
    //## auto_generated 
    public  Probe(RiJThread p_thread) {
        reactive = new Reactive(p_thread);
    }
    
    //## auto_generated 
    public boolean getIsBroken() {
        return isBroken;
    }
    
    //## auto_generated 
    public void setIsBroken(boolean p_isBroken) {
        isBroken = p_isBroken;
    }
    
    //## auto_generated 
    public double getTemperature() {
        return temperature;
    }
    
    //## auto_generated 
    public void setTemperature(double p_temperature) {
        temperature = p_temperature;
    }
    
    //## auto_generated 
    public TemperatureMeasurer getParent() {
        return parent;
    }
    
    //## auto_generated 
    public void __setParent(TemperatureMeasurer p_TemperatureMeasurer) {
        parent = p_TemperatureMeasurer;
    }
    
    //## auto_generated 
    public void _setParent(TemperatureMeasurer p_TemperatureMeasurer) {
        if(parent != null)
            {
                parent._removeItsProbe(this);
            }
        __setParent(p_TemperatureMeasurer);
    }
    
    //## auto_generated 
    public void setParent(TemperatureMeasurer p_TemperatureMeasurer) {
        if(p_TemperatureMeasurer != null)
            {
                p_TemperatureMeasurer._addItsProbe(this);
            }
        _setParent(p_TemperatureMeasurer);
    }
    
    //## auto_generated 
    public void _clearParent() {
        parent = null;
    }
    
    //## auto_generated 
    public boolean startBehavior() {
        boolean done = false;
        done = reactive.startBehavior();
        return done;
    }
    
    //## ignore 
    public class Reactive extends RiJStateReactive {
        
        // Default constructor 
        public Reactive() {
            this(RiJMainThread.instance());
        }
        
        
        // Constructors
        
        public  Reactive(RiJThread p_thread) {
            super(p_thread);
            initStatechart();
        }
        
        //## statechart_method 
        public boolean isIn(int state) {
            if(rootState_subState == state)
                {
                    return true;
                }
            return false;
        }
        
        //## statechart_method 
        public boolean isCompleted(int state) {
            return true;
        }
        
        //## statechart_method 
        public void rootState_entDef() {
            {
                rootState_enter();
                rootStateEntDef();
            }
        }
        
        //## statechart_method 
        public int rootState_dispatchEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            switch (rootState_active) {
                case WaitForNewTemperature:
                {
                    res = WaitForNewTemperature_takeEvent(id);
                }
                break;
                case sendaction_7:
                {
                    res = sendaction_7_takeEvent(id);
                }
                break;
                case sendaction_8:
                {
                    res = sendaction_8_takeEvent(id);
                }
                break;
                case sendaction_9:
                {
                    res = sendaction_9_takeEvent(id);
                }
                break;
                default:
                    break;
            }
            return res;
        }
        
        //## auto_generated 
        protected void initStatechart() {
            rootState_subState = RiJNonState;
            rootState_active = RiJNonState;
        }
        
        //## statechart_method 
        public void sendaction_8_entDef() {
            sendaction_8_enter();
        }
        
        //## statechart_method 
        public void WaitForNewTemperatureExit() {
        }
        
        //## statechart_method 
        public int sendaction_8_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            return res;
        }
        
        //## statechart_method 
        public void sendaction_7Exit() {
            itsRiJThread.unschedTimeout(Probe_Timeout_sendaction_7_id, this);
        }
        
        //## statechart_method 
        public void WaitForNewTemperature_enter() {
            rootState_subState = WaitForNewTemperature;
            rootState_active = WaitForNewTemperature;
            WaitForNewTemperatureEnter();
        }
        
        //## statechart_method 
        public void WaitForNewTemperature_entDef() {
            WaitForNewTemperature_enter();
        }
        
        //## statechart_method 
        public void sendaction_8Exit() {
        }
        
        //## statechart_method 
        public int rootState_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            return res;
        }
        
        //## statechart_method 
        public void sendaction_9Exit() {
        }
        
        //## statechart_method 
        public void sendaction_9_entDef() {
            sendaction_9_enter();
        }
        
        //## statechart_method 
        public int sendaction_7_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(RiJEvent.TIMEOUT_EVENT_ID))
                {
                    res = sendaction_7TakeRiJTimeout();
                }
            
            return res;
        }
        
        //## statechart_method 
        public void sendaction_9Enter() {
            //#[ state sendaction_9.(Entry) 
            parent.gen(new Default.ProbeSYN(Probe.this));
            //#]
        }
        
        //## statechart_method 
        public void rootState_enter() {
            rootStateEnter();
        }
        
        //## statechart_method 
        public void rootStateEnter() {
        }
        
        //## statechart_method 
        public void sendaction_7_enter() {
            rootState_subState = sendaction_7;
            rootState_active = sendaction_7;
            sendaction_7Enter();
        }
        
        //## statechart_method 
        public void sendaction_8_enter() {
            rootState_subState = sendaction_8;
            rootState_active = sendaction_8;
            sendaction_8Enter();
        }
        
        //## statechart_method 
        public void sendaction_8Enter() {
            //#[ state sendaction_8.(Entry) 
            parent.gen(new Default.ProbeBroken(Probe.this));
            //#]
        }
        
        //## statechart_method 
        public int WaitForNewTemperature_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(ProbeTemperatureChanged.ProbeTemperatureChanged_Default_id))
                {
                    res = WaitForNewTemperatureTakeProbeTemperatureChanged();
                }
            
            return res;
        }
        
        //## statechart_method 
        public void sendaction_7Enter() {
            //#[ state sendaction_7.(Entry) 
            gen(new Default.ProbeTemperatureChanged(Probe.this,temperature));
            //#]
            itsRiJThread.schedTimeout(200, Probe_Timeout_sendaction_7_id, this, null);
        }
        
        //## statechart_method 
        public void sendaction_9_enter() {
            rootState_subState = sendaction_9;
            rootState_active = sendaction_9;
            sendaction_9Enter();
        }
        
        //## statechart_method 
        public void sendaction_7_entDef() {
            sendaction_7_enter();
        }
        
        //## statechart_method 
        public void sendaction_9_exit() {
            sendaction_9Exit();
        }
        
        //## statechart_method 
        public void WaitForNewTemperatureEnter() {
        }
        
        //## statechart_method 
        public void rootStateEntDef() {
            sendaction_9_entDef();
        }
        
        //## statechart_method 
        public void sendaction_8_exit() {
            sendaction_8Exit();
        }
        
        //## statechart_method 
        public void sendaction_7_exit() {
            sendaction_7Exit();
        }
        
        //## statechart_method 
        public int WaitForNewTemperatureTakeProbeTemperatureChanged() {
            ProbeTemperatureChanged params = (ProbeTemperatureChanged) event;
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            //## transition 3 
            if(isBroken == false)
                {
                    WaitForNewTemperature_exit();
                    //#[ transition 1 
                    temperature=params.temperature;
                    //#]
                    sendaction_7_entDef();
                    res = RiJStateReactive.TAKE_EVENT_COMPLETE;
                }
            else
                {
                    //## transition 4 
                    if(isBroken == true)
                        {
                            WaitForNewTemperature_exit();
                            //#[ transition 1 
                            temperature=params.temperature;
                            //#]
                            sendaction_8_entDef();
                            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
                        }
                }
            return res;
        }
        
        //## statechart_method 
        public int sendaction_9_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(ProbeSYNACK.ProbeSYNACK_Default_id))
                {
                    res = sendaction_9TakeProbeSYNACK();
                }
            
            return res;
        }
        
        //## statechart_method 
        public void WaitForNewTemperature_exit() {
            WaitForNewTemperatureExit();
        }
        
        //## statechart_method 
        public void rootStateExit() {
        }
        
        //## statechart_method 
        public int sendaction_7TakeRiJTimeout() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.getTimeoutId() == Probe_Timeout_sendaction_7_id)
                {
                    sendaction_7_exit();
                    WaitForNewTemperature_entDef();
                    res = RiJStateReactive.TAKE_EVENT_COMPLETE;
                }
            return res;
        }
        
        //## statechart_method 
        public int sendaction_9TakeProbeSYNACK() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            sendaction_9_exit();
            WaitForNewTemperature_entDef();
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
    }
}
/*********************************************************************
	File Path	: DefaultComponent/DefaultConfig/Default/Probe.java
*********************************************************************/

